<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
<div id="content">
    <div id="icon" class="icon32"><br/></div><h2>编辑分类</h2>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">列表</a></li>
            <li><a href="#tabs-2">添加</a></li>
            <li><a href="#tabs-3">编辑</a></li>
        </ul>
        <div id="tabs-1">
            <table class="list-table">
                <thead class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="30%">名称</th>
                        <th width="40%">描述</th>
                        <th width="10%">排序</th>
                        <th width="15%">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($this->categoryList)) : ?>
                        <?php foreach ($this->categoryList as $category) : ?>
                    <tr>
                        <td><?php echo $this->escape($category->categoryId) ?></td>
                        <td><?php echo $this->escape($category->categoryName) ?></td>
                        <td><?php echo $this->escape($category->categoryDesc) ?></td>
                        <td><?php echo $this->escape($category->displayOrder) ?></td>
                        <td>
                            <a href="javascript:void(0)" onclick="editCategory(<?php echo $this->escape($category->categoryId) ?>)">编辑</a> |
                            <a href="javascript:if(confirm('你确实要删除这个分类吗?'))location='/backend/del/category/id/<?php echo $this->escape($category->categoryId) ?>'">删除</a>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
                <tfoot class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="30%">名称</th>
                        <th width="40%">描述</th>
                        <th width="10%">排序</th>
                        <th width="15%">操作</th>
                    </tr>
                </tfoot>
            </table>
            <?php if(($this->categoryId == 0) && !empty($this->categoryList)) echo $this->paginationControl($this->categoryList,'Elastic','pagebar.phtml'); ?>
        </div>
        <div id="tabs-2" class="editor-area">
            <form action="/backend/add/category/" method="post" onsubmit="return submitAdd();">
                <div class="titlebox">
                    <h3><span>名称</span></h3>
                    <input type="text" class="title" id="add_category_name" name="category_name" autocomplete="off" value="" tabindex="1" size="30" value="" />
                </div>
                <div>
                    <h3><span>描述</span></h3>
                    <input type="text" class="title" id="add_category_desc" name="category_desc" autocomplete="off" value="" tabindex="1" size="30" value="" />
                </div>
                <div id="other">
                    <h3><span>父类</span></h3>
                    <?php if(null !== $this->parentCategory): ?>
                    <ul>
                            <?php foreach ($this->parentCategory as $parent) : ?>
                        <li><input type="radio" id="add_parent_id" name="parent_id" value="<?php echo $this->escape($parent->categoryId) ?>"><?php echo $this->escape($parent->categoryName) ?></li>
                            <?php endforeach; ?>
                    </ul>
                    <?php else: ?>
                    暂无分类，无法选择父类，请先添加分类!
                    <?php endif; ?>
                </div>
                <div id="add-message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="add-error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="添加" name="publish"/>
                </div>
            </form>
        </div>
        <div id="tabs-3" class="editor-area">
            <form action="/backend/edit/category/" method="post" onsubmit="return submitEdit();">
                <div class="titlebox">
                    <h3><span>名称</span></h3>
                    <input type="text" class="title" id="edit_category_name" name="category_name" autocomplete="off" value="<?php echo $this->escape($this->categoryInfo->categoryName) ?>" tabindex="1" size="30" />
                </div>
                <div>
                    <h3><span>描述</span></h3>
                    <input type="text" class="title" id="edit_category_desc" name="category_desc" autocomplete="off" value="<?php echo $this->escape($this->categoryInfo->categoryDesc) ?>" tabindex="1" size="30" />
                </div>
                <div>
                    <h3><span>排序</span></h3>
                    <input type="text" class="title" id="edit_display_order" name="display_order" autocomplete="off" value="<?php echo $this->escape($this->categoryInfo->displayOrder) ?>" tabindex="1" size="2" />
                </div>
                <div id="other">
                    <h3><span>父类</span></h3>
                    <ul>
                        <li><input type="radio" id="parent_id" name="parent_id" value="0" <?php if(0 == $this->categoryInfo->parentId): ?>checked="true"<?php endif; ?>>无</li>
                        <?php foreach ($this->parentCategory as $parent) : ?>
                        <li><input type="radio" id="parent_id" name="parent_id" value="<?php echo $this->escape($parent->categoryId) ?>" <?php if($parent->categoryId == $this->categoryInfo->parentId): ?>checked="true"<?php endif; ?>><?php echo $this->escape($parent->categoryName) ?></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
                <div id="edit-message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="edit-error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="修改" name="publish"/>
                    <input id="categoryId" type="hidden" value="<?php echo $this->escape($this->categoryInfo->categoryId) ?>" name="categoryId"/>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#tabs").tabs({
<?php if($this->categoryId > 0): ?>
            disabled: [0],
<?php else: ?>
            disabled: [2],
<?php endif; ?>
            collapsible: true
        });
    });

    function submitAdd(){
        if ($("#add_category_name").val() == '') {
            $("#add-message-box").show();
            $("#add-error-message").empty();
            $("#add-error-message").append("请输入分类名称!");
            return false;
        } else if ($("#add_category_desc").val() == '') {
            $("#add-message-box").show();
            $("#add-error-message").empty();
            $("#add-error-message").append("请输入分类描述!");
            return false;
        } else {
            return true;
        }
    }

    function submitEdit(){
        if ($("#edit_category_name").val() == '') {
            $("#edit-message-box").show();
            $("#edit-error-message").empty();
            $("#edit-error-message").append("请输入分类名称!");
            return false;
        } else if ($("#edit_category_desc").val() == '') {
            $("#edit-message-box").show();
            $("#edit-error-message").empty();
            $("#edit-error-message").append("请输入分类描述!");
            return false;
        } else if ($("#edit_display_order").val() == '') {
            $("#edit-message-box").show();
            $("#edit-error-message").empty();
            $("#edit-error-message").append("请输入分类排序!");
            return false;
        } else {
            return true;
        }
    }

    function editCategory(id){
        $("#tabs").tabs('option', 'disable', []);
        window.location.href = '/backend/list/category/id/'+ id + '#tabs-' + 3;
    }
</script>
<?php echo $this->render('footer.phtml'); ?>